For problem C, I just got AC using the following greedy strategy:



For all lengths N starting at 1
   let the string s be ""
   For all positions i from 0 to N-1
      For all characters c starting from 'a' 
          if s+c can be completed to have N characters and at least the given number of different substrings, let s be s+c, and break
   if s has exactly the given number of different strings, return s




The algorithm is not correct, in the sense that if this algorithm returns a string of size N, that string is the minimal string of size N with exactly the given number of different substrings, but it is not guaranteed that N is minimal. However, it can be seen from looking at the output that for all n between 1 and 300, excluding 16, the greedy algorithm actually produces a string of minimal length. For n=16, the answer can be brute-forced. 
